<template>
  <div>
    <!-- banner -->
    <div
      class="banner"
      :style="cover"
    >
      <h1 class="banner-title">
        <span v-if="currentPageInfo.pageTitle">{{ currentPageInfo.pageTitle }}</span>
        <span v-else>友情链接</span>
      </h1>
      <!-- 主屏幕副标题 -->
      <div class="banner-title-second">
        <span v-if="currentPageInfo.pageIntro">
          {{ currentPageInfo.pageIntro }}
        </span>
      </div>
    </div>
    <!-- 链接列表 -->
    <v-card class="blog-container">
      <!--      <div class="link-title mb-1">-->
      <!--        <v-icon color="blue">-->
      <!--          mdi-link-variant-->
      <!--        </v-icon>-->
      <!--        大佬链接-->
      <!--      </div>-->
      <v-row class="link-container">
        <v-col
          v-for="item of friendLinkList"
          :key="item.url"
          class="link-wrapper"
          md="4"
          cols="12"
        >
          <a
            :href="item.webUrl"
            target="_blank"
          >
            <v-avatar
              size="65"
              class="link-avatar"
            >
              <img :src="item.logoUrl">
            </v-avatar>
            <div style="width:100%;z-index:10;">
              <div class="link-name">{{ item.userName }}</div>
              <div class="link-intro">{{ item.intro }}</div>
            </div>
          </a>
        </v-col>
      </v-row>
      <!-- 说明 -->
      <div class="link-title mt-4 mb-4">
        <v-icon color="blue">
          mdi-dots-horizontal-circle
        </v-icon>
        添加友链
      </div>
      <div class="webInfoClass">
<!--        <div>网站名称：{{ blogInfo.basicInfo.webName }}</div>-->
        <div>网站名称：小徐个人博客</div>
        <div>网站简介：{{ blogInfo.basicInfo.intro }}</div>
        <div>网站地址：www.xqijun.top</div>
        <div>网站头像：{{ blogInfo.authorInfo.avatar }}</div>
      </div>
      <div class="mt-5 mb-5">
        <!--        需要交换友链的可点击-->
        <!--        <a-->
        <!--          style="color: #409eff"-->
        <!--          @click="onclick"-->
        <!--        >此处</a>💖<br>-->
      </div>
      <hr>
      <!-- 评论 -->
      <comment
        ref="commentRef_"
        :comment-list="commentList"
        :count="count"
        :article-id="0"
        :ownership="2"
        @reloadComment="listComment"
      />
    </v-card>

    <div>
      <el-dialog
        width="50%"
        center
        title="申请友链"
        :visible.sync="dialogFormVisible"
      >
        <el-form
          ref="dataForm"
          :rules="rules"
          :model="link"
        >
          <el-form-item
            label="网站名称"
            prop="name"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="link.name"
              autocomplete="off"
            />
          </el-form-item>
          <el-form-item
            label="网站头像"
            prop="avatar"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="link.avatar"
              autocomplete="off"
            />
          </el-form-item>
          <el-form-item
            label="邮箱地址"
            prop="email"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="link.email"
              autocomplete="off"
            />
          </el-form-item>
          <el-form-item
            label="网站简介"
            prop="info"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="link.info"
              autocomplete="off"
            />
          </el-form-item>
          <el-form-item
            label="网站地址"
            prop="url"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="link.url"
              autocomplete="off"
            />
          </el-form-item>
        </el-form>
        <div
          slot="footer"
          class="dialog-footer"
        >
          <el-button @click="dialogFormVisible = false">
            取 消
          </el-button>
          <el-button
            type="primary"
            @click="submit"
          >
            确 定
          </el-button>
        </div>
      </el-dialog>
    </div>
    <!--      <blockquote class="mb-10">
              友链信息展示需要，你的信息格式要包含：名称、介绍、链接、头像
            </blockquote>-->
  </div>
</template>

<script>
import {msgList} from '@/api'
import {metaInfo} from '@/config/BlogConstant'
import Comment from '@/components/Comment.vue'

export default {
  components: {Comment},
  metaInfo:metaInfo,
  data: function() {
    return {
      friendLinkList: [],
      formLabelWidth: '120px',
      img: process.env.VUE_APP_IMG_API,
      commentList: [],
      dialogFormVisible: false,
      count: 0,
      currentPageInfo:{},
      link: {
        url: null,
        name: null,
        avatar: null,
        info: null,
        email: null
      },
      rules:{
        'name': [{required: true,message: '必填字段',trigger: 'blur'}],
        'email': [
          {required: true,message: '必填字段',trigger: 'blur'},
          {pattern: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/, message: '填写正确的邮箱'}
        ],
        'info': [{required: true,message: '必填字段',trigger: 'blur'}],
        'url': [
          {required: true,message: '必填字段',trigger: 'blur'},
          {pattern:/^((https|http|ftp|rtsp|mms){0,1}(:\/\/){0,1})www\.(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\\/])+$/, message: '填写正确的网址'}
        ],
        'avatar': [{required: true,message: '必填字段',trigger: 'blur'}]
      }
    }
  },
  computed: {
    blogInfo() {
      return this.$store.state.blogInfo
    },
    cover() {
      let cover = ''
      this.$store.state.blogInfo.pageInfo.forEach(item => {
        if (item.pageKey === 'friend') {
          cover = item.headerImgUrl
          this.currentPageInfo = item
        }
      })
      return 'background: url(' + cover + ') center center / cover no-repeat'
    }
  },
  created() {
    this.listFriendLink()
    this.listComment()
  },
  methods: {
    listComment() {
      msgList(0,2).then(res=>{
        let resData = res.data
        this.commentList = resData.data
        this.count = resData.data.length
      })
    },
    onclick:function(){
      this.link={}
      // this.dialogFormVisible = true
    },
    listFriendLink() {
      this.friendLinkList = this.blogInfo.friendInfo
    },
    submit:function(){
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          addLink(this.link).then(res => {
            this.$toast({type: 'success', message: '申请成功,通过申请将邮件告知!!'})
            this.dialogFormVisible = false
          }).catch(err => {
            this.$toast({type: 'error', message: err.message})
          })
        } else {
          this.$toast({type: 'error', message: '存在必填字段!!!'})
        }
      })
    },
  }
}
</script>

<style scoped lang="scss">
blockquote {
  line-height: 2;
  margin: 0;
  font-size: 15px;
  border-left: 0.2rem solid #49b1f5;
  padding: 10px 1rem !important;
  background-color: #ecf7fe;
  border-radius: 4px;
}

.webInfoClass{
  line-height: 2;
  margin: 0;
  font-size: 15px;
  border-left: 0.2rem solid #49b1f5;
  padding: 10px 1rem !important;
  background-color: #f2f2f2;
  border-radius: 4px;
  color: #343434 !important;
}

.link-title {
  color: #344c67;
  font-size: 21px;
  font-weight: bold;
  line-height: 2;
}

.link-container {
  margin: 10px 10px 0;
}

.link-wrapper {
  position: relative;
  transition: all 0.3s;
  border-radius: 8px;
}

.link-avatar {
  margin-top: 5px;
  margin-left: 10px;
  transition: all 0.5s;
}

@media (max-width: 759px) {
  .link-avatar {
    margin-left: 30px;
  }
}

.link-name {
  text-align: left;
  font-size: 1.1rem;
  font-weight: bold;
  margin-left: 16px;
  margin-top: 5px;
  z-index: 100;
}

.link-intro {
  text-align: left;
  padding: 3px 0 0 16px;
  height: 50px;
  font-size: 14px;
  color: #1f2d3d;
  width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.link-wrapper:hover a {
  color: #fff;
}

.link-wrapper:hover .link-intro {
  color: #fff;
}

.link-wrapper:hover .link-avatar {
  transform: rotate(360deg);
}

.link-wrapper a {
  color: #333;
  text-decoration: none;
  display: flex;
  height: 100%;
  width: 100%;
}

.link-wrapper:hover {
  box-shadow: 0 2px 20px #49b1f5;
}

.link-wrapper:hover:before {
  transform: scale(1);
}

.link-wrapper:before {
  position: absolute;
  border-radius: 8px;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: #49b1f5 !important;
  content: "";
  transition-timing-function: ease-out;
  transition-duration: 0.3s;
  transition-property: transform;
  transform: scale(0);
}
</style>
